//
//  CommentTableView.m
//  Weibo
//
//  Created by taoshanchang on 15/2/1.
//  Copyright (c) 2015年 taoshanchang. All rights reserved.
//

#import "CommentTableView.h"
#import "CommentCell.h"
#import "CommentModel.h"
#import "UIViewExt.h"

@implementation CommentTableView

-(id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style{
    self = [super initWithFrame:frame style:style];
    if(self){
        
    }
    return self;
}


#pragma mark - UITableView delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.data.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *identify = @"commentCell";
    CommentCell *cell = [tableView dequeueReusableCellWithIdentifier:identify];
    if(cell == nil){
        cell = [[CommentCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identify];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    CommentModel *model = [self.data objectAtIndex:indexPath.row];
    cell.commentModel = model;
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    float h = [CommentCell getCommentHeight:[self.data objectAtIndex:indexPath.row]];
    return h+50;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.width, 40)];
    view.backgroundColor = [UIColor whiteColor];
    
    UILabel *commentCount = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 100, 20)];
    commentCount.backgroundColor = [UIColor clearColor];
    commentCount.font = [UIFont systemFontOfSize:16.0f];
    commentCount.textColor = [UIColor blueColor];
    NSNumber *total = [self.commentDic objectForKey:@"total_number"];
    commentCount.text = [NSString stringWithFormat:@"评论:%@",total];
    
    UIImageView *separeView = [[UIImageView alloc] initWithFrame:CGRectMake(0, view.bottom-1, view.width, 1)];
    separeView.image = [UIImage imageNamed:@"userinfo_header_separator"];
    [view addSubview:commentCount];
    [view addSubview:separeView];
    
    return view;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 40;
}

@end
